package com.libbase.extension

import android.content.Context
import android.content.ContextWrapper
import android.net.Uri
import android.net.Uri.Builder
import com.libbase.utils.FileUtils

fun Uri.getQueryItems(keys: Set<String>? = null): Map<String, String>? {
    if (queryParameterNames.size <= 0) {
        return null
    }

    val names: Set<String> = keys ?: queryParameterNames

    val queryItems: MutableMap<String, String> = mutableMapOf()
    names.forEach { name ->
        val value = getQueryParameter(name)
        if (value != null) {
            queryItems[name] = value
        }
    }

    return queryItems
}

fun Uri.addUrlParameters(params: Map<String, String>): Uri {
    val uriBuilder = buildUpon()
    params.forEach {
        uriBuilder.appendQueryParameter(it.key, it.value)
    }

    return uriBuilder.build()
}